//# sourceURL=http://uMapApp/Module/Maintain/MaintainStaModule
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "uEarth/uEarth"
    , "../Module"
    , "../../UI/Panel/FloatPanel"
    , "../../UI/Panel/PanelBlock/ListBlock"
    , "../../UI/Panel/PanelBlock/PanelBlock"
    , "../../UI/Panel/PanelBlock/PropertiesBlock"
    , "../../UI/Panel/PanelBlock/ChartBlock"
    , "../../UI/Panel/PanelBlock/DataPanelBlock"
    , "../../UI/Panel/Item/ListItem"
    , "../../UI/Layer"
    , "../Road/StakeNumPanel"
    , "./Maintain"
    , "./MaintainBlock"
    , "../../UI/QueryNode"
], function (
    mhjs,
    uMap,
    uEarth,
    Module,
    FloatPanel,
    ListBlock,
    PanelBlock,
    PropertiesBlock
    , ChartBlock
    , DataPanelBlock
    , ListItem
    , Layer
    , StakeNumPanel
    , Maintain
    , MaintainBlock
    , QueryNode
) {

    function MaintainStaModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "道路养护";
        _this.icon = _this.app.icons.maintain;

        _this.panels = [];
        _this.items = [];
        _this.currentStatisticsOption = {};

        //全局数据面板
        _this.globeChartPanel = new FloatPanel({"class": "leftPanel", "showMinMax": true, "title": "统计图表"});
        _this.globeChartPanel.damageTypeBlock = new ChartBlock({
            "title": "病害类型",
            "chart": {
                "height"     : 200,
                "width"      : 350,
                "chartOption": {
                    legend : {
                        type     : "scroll",
                        orient   : "vertical",
                        left     : "left",
                        textStyle: {
                            color: "#fff"
                        }
                    },
                    grid   : {
                        top         : "0",
                        left        : "0",
                        right       : "0",
                        bottom      : "0",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    series : {
                        type  : "pie",
                        center: ["50%", "50%"],
                        label : {
                            formatter: "{b}: {d}%",
                            color    : "#fff",
                            overflow : "break"
                        }
                    }
                }
            }
        });

        _this.globeChartPanel.damageTypeBlock.chart.chart.on("click", "series", function (event) {

            if (_this.listPanel.listBlock.damageMainTypeSelect.value !== event.name) {
                _this.listPanel.listBlock.damageMainTypeSelect.selectValue(event.name);
            } else {
                _this.listPanel.listBlock.damageMainTypeSelect.selectValue("");
            }


        });

        _this.globeChartPanel.damageDegreeBlock = new ChartBlock({
            "title": "病害程度",
            "chart": {
                "height"     : 200,
                "width"      : 350,
                "chartOption": {
                    legend : {
                        orient   : "vertical",
                        left     : "left",
                        textStyle: {
                            color: "#fff"
                        }
                    },
                    grid   : {
                        top         : "0",
                        left        : "0",
                        right       : "0",
                        bottom      : "0",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    series : {
                        type  : "pie",
                        center: ["50%", "50%"],
                        label : {
                            formatter: "{b}: {d}%",
                            color    : "#fff",
                            overflow : "break"
                        }
                    }
                }
            }
        });

        _this.globeChartPanel.damageDegreeBlock.chart.chart.on("click", "series", function (event) {
            if (_this.listPanel.listBlock.damageDegreeSelect.value !== event.name) {
                _this.listPanel.listBlock.damageDegreeSelect.selectValue(event.name);
            } else {
                _this.listPanel.listBlock.damageDegreeSelect.selectValue("");
            }
        });

        _this.globeChartPanel.yearBlock = new ChartBlock({
            "title": "历史统计",
            "chart": {
                "height"     : 200,
                "width"      : 350,
                "chartOption": {
                    legend : {
                        orient   : "vertical",
                        left     : "left",
                        textStyle: {
                            color: "#fff"
                        }
                    },
                    grid   : {
                        top         : "0",
                        left        : "0",
                        right       : "0",
                        bottom      : "0",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    series : {
                        type  : "pie",
                        center: ["50%", "50%"],
                        label : {
                            formatter: "{b}: {d}%",
                            color    : "#fff",
                            overflow : "break"
                        }
                    }
                }
            }
        });

        _this.globeChartPanel
            .append(_this.globeChartPanel.damageTypeBlock)
            .append(_this.globeChartPanel.damageDegreeBlock)
            .append(_this.globeChartPanel.yearBlock)
        ;

        _this.app.ui.layout.left.append(_this.globeChartPanel);
        _this.panels.push(_this.globeChartPanel);

        //整体数据概览
        _this.globeDataPanel = new FloatPanel({"class": "MaintainStaModule globeDataPanel", "showClose": true});

        _this.globeDataPanel.label = new mhjs.Div({"class": "label"});
        _this.globeDataPanel.label.text("关键指标");

        _this.globeDataPanel.damageCountData = new DataPanelBlock({
            label  : "病害数量"
            , count: "0"
            , unit : "(处)"
        });

        _this.globeDataPanel.damageDistanceData = new DataPanelBlock({
            label  : "病害里程"
            , count: "0"
            , unit : "km"
        });

        _this.globeDataPanel.damagePercentData = new DataPanelBlock({
            label  : "破损占比"
            , count: "0"
            , unit : "%"
        });

        _this.globeDataPanel
            .append(_this.globeDataPanel.label)
            .append(_this.globeDataPanel.damageCountData)
            .append(_this.globeDataPanel.damageDistanceData)
            .append(_this.globeDataPanel.damagePercentData)
        ;

        _this.app.ui.layout.top.append(_this.globeDataPanel);
        _this.panels.push(_this.globeDataPanel);

        //整体功能按钮
        _this.globeButtonPanel = new FloatPanel({"class": "MaintainStaModule globeButtonPanel"});

        _this.globeButtonPanel.label = new mhjs.Div({"class": "label"});
        _this.globeButtonPanel.label.text("筛选");

        _this.directionDic = [
            {
                "text" : "双向",
                "value": ""
            },
            {
                "text" : "上行",
                "value": "U"
            }, {
                "text" : "下行",
                "value": "D"
            }
        ];

        _this.globeButtonPanel.directSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.directSelect.setList(_this.directionDic);

        _this.roadLineDic = [
            {
                "text" : "所有车道",
                "value": ""
            },
            {
                "text" : "单向整体",
                "value": "0"
            },
            {
                "text" : "第一车道",
                "value": "1"
            },
            {
                "text" : "第二车道",
                "value": "2"
            },
            {
                "text" : "第三车道",
                "value": "3"
            }
        ];

        _this.globeButtonPanel.yearSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.yearSelect.setList([
            {
                "text" : "全部",
                "value": ""
            },
            {
                "text" : "2020",
                "value": "2020"
            }, {
                "text" : "2021",
                "value": "2021"
            }, {
                "text" : "2022",
                "value": "2022"
            }
        ]);

        _this.globeButtonPanel.yearSelect.selectValue("2022");

        _this.globeButtonPanel.roadLineSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.roadLineSelect.setList(_this.roadLineDic);

        _this.globeButtonPanel.typeSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.damageMainTypeSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.damageTypeSelect = new mhjs.Select({"class": "select"});

        _this.globeButtonPanel.startStakeNumInput = new mhjs.Input({"class": "input"});
        _this.globeButtonPanel.startStakeNumInput.placeholder = "请输入起点桩号";

        _this.globeButtonPanel.stopStakeNumInput = new mhjs.Input({"class": "input"});
        _this.globeButtonPanel.stopStakeNumInput.placeholder = "请输入终点桩号";

        _this.globeButtonPanel.globeDataButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.globeDataButton.text("总览");

        _this.globeButtonPanel.globeDataButton.on("click", function () {
            _this.globeDataPanel.toggle();
        });

        _this.globeButtonPanel.statisticsButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.statisticsButton.text("统计");

        _this.globeButtonPanel.statisticsButton.on("click", function () {
            _this.renderData({
                "directionCode"      : _this.globeButtonPanel.directSelect.value
                , "roadLineNum"      : _this.globeButtonPanel.roadLineSelect.value
                , "startStakeNum"    : _this.globeButtonPanel.startStakeNumInput.value
                , "endStakeNum"      : _this.globeButtonPanel.stopStakeNumInput.value
                , "type"             : _this.globeButtonPanel.typeSelect.value
                , "diseaseParentType": _this.globeButtonPanel.damageMainTypeSelect.value
                , "diseaseType"      : _this.globeButtonPanel.damageTypeSelect.value
                , "year"             : _this.globeButtonPanel.yearSelect.value
            }, function () {
                _this.openStatistics();
            });
        });

        _this.globeButtonPanel.detailButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.detailButton.text("明细");

        _this.globeButtonPanel.detailButton.on("click", function () {
            _this.renderData({
                "directionCode"     : _this.globeButtonPanel.directSelect.value
                , "roadLineNum"     : _this.globeButtonPanel.roadLineSelect.value
                , "startStakeNum"   : _this.globeButtonPanel.startStakeNumInput.value
                , "endStakeNum"     : _this.globeButtonPanel.stopStakeNumInput.value
                , "type"            : _this.globeButtonPanel.typeSelect.value
                , "diseaseParentType": _this.globeButtonPanel.damageMainTypeSelect.value
                , "diseaseType"      : _this.globeButtonPanel.damageTypeSelect.value
                , "year"            : _this.globeButtonPanel.yearSelect.value
            }, function () {
                _this.openDetail();
            });
        });

        _this.globeButtonPanel
            .append(_this.globeButtonPanel.label)
            .append(_this.globeButtonPanel.directSelect)
            .append(_this.globeButtonPanel.roadLineSelect)
            .append(_this.globeButtonPanel.startStakeNumInput)
            .append(_this.globeButtonPanel.stopStakeNumInput)
            .append(_this.globeButtonPanel.typeSelect)
            .append(_this.globeButtonPanel.damageMainTypeSelect)
            .append(_this.globeButtonPanel.damageTypeSelect)
            .append(_this.globeButtonPanel.yearSelect)
            .append(_this.globeButtonPanel.globeDataButton)
            .append(_this.globeButtonPanel.statisticsButton)
            .append(_this.globeButtonPanel.detailButton)
        ;

        _this.app.ui.layout.bottom.append(_this.globeButtonPanel);
        _this.panels.push(_this.globeButtonPanel);

        //桩号导航
        _this.stakeNumPanel = new StakeNumPanel({
            "app"      : _this.app,
            "class"    : "MaintainStaModule",
            "direction": 90
        });

        _this.app.ui.layout.top.append(_this.stakeNumPanel);
        _this.panels.push(_this.stakeNumPanel);

        _this.listPanel = new FloatPanel({
            "class": "MaintainStaModule rightPanel", "showMinMax": true, "title": "明细数据"
        });
        _this.listPanel.listBlock = new ListBlock({"class": "fullBlock"});
        _this.listPanel.listBlock.title = _this.title;
        _this.listPanel.append(_this.listPanel.listBlock);

        _this.listPanel.on("close", function () {
            _this.closePanel();
        });

        _this.listPanel.listBlock.filter = {
            "param": "maintain.searchKey"
        };

        _this.listPanel.listBlock.sorter = {
            "param": {
                "value": "maintain.sortKey",
                "label": "桩号/车道"
            }
        };

        _this.listPanel.listBlock.damageMainTypeSelect = new mhjs.Select({"class": "select"});
        _this.listPanel.listBlock.damageMainTypeSelect.on("select", function (select) {
            _this.listPanel.listBlock.toggleDamage();
        });

        _this.listPanel.listBlock.damageDegreeSelect = new mhjs.Select({"class": "select"});
        _this.listPanel.listBlock.damageDegreeSelect.on("select", function (select) {
            _this.listPanel.listBlock.toggleDamage();
        });

        _this.listPanel.listBlock.toggleDamage = function () {


            $.each(_this.listPanel.listBlock.list, function (i, item) {

                if (
                    (_this.listPanel.listBlock.damageMainTypeSelect.value === "" || item.maintain["病害主类型"] === _this.listPanel.listBlock.damageMainTypeSelect.value)
                    &&
                    (_this.listPanel.listBlock.damageDegreeSelect.value === "" || item.maintain["病害程度"] === _this.listPanel.listBlock.damageDegreeSelect.value)
                ) {
                    item.show();
                } else {
                    item.hide();
                }

            });


        };

        _this.listPanel.listBlock.sorter.before(_this.listPanel.listBlock.damageMainTypeSelect.dom);
        _this.listPanel.listBlock.sorter.before(_this.listPanel.listBlock.damageDegreeSelect.dom);

        _this.panels.push(_this.listPanel);

        _this.statisticsPanel = new FloatPanel({
            "class": "MaintainStaModule statisticsPanel"
        });

        _this.statisticsPanel.tableBlock = new PanelBlock({"class": "statisticsTableBlock"});
        _this.statisticsPanel.tableBlock.title = "单车道各检测指标超标数量统计";

        _this.statisticsPanel.tableBlock.exportButton = new mhjs.Div({"class": "button"});
        _this.statisticsPanel.tableBlock.exportButton.text("导出");

        _this.statisticsPanel.tableBlock.export = function () {

            var output = "";

            var head = [];

            $.each(_this.statisticsPanel.tableBlock.ui.wrap.find("thead th"), function (i, td) {

                head.push($(td).text());
                if ($(td).attr("colspan")) {
                    for (var j = 0; j < Number($(td).attr("colspan")) - 1; j++) {
                        head.push("");
                    }
                }
            });

            output += head.join(",");

            $.each(_this.statisticsPanel.tableBlock.ui.wrap.find("tbody tr:visible"), function (i, tr) {

                var line = [];

                $.each($(tr).find("td"), function (j, td) {
                    line.push($(td).text());
                });

                output += "\n" + line.join(",");

            });

            mhjs.SaveFile(output, _this.statisticsPanel.tableBlock.title + "_" + new Date().getTime() + ".csv");

        };

        _this.statisticsPanel.tableBlock.exportButton.on("click", function () {
            _this.statisticsPanel.tableBlock.export();
        });

        _this.statisticsPanel.tableBlock.addButton(_this.statisticsPanel.tableBlock.exportButton);

        _this.statisticsPanel
            .append(_this.statisticsPanel.tableBlock)
        ;

        _this.app.ui.layout.bottom.append(_this.statisticsPanel);
        _this.panels.push(_this.statisticsPanel);

        // _this.detailPanel = new FloatPanel({"class": "leftPanel"});
        // _this.detailPanel.propertiesBlock = new PropertiesBlock({"class": "fullBlock"});
        // _this.detailPanel.append(_this.detailPanel.propertiesBlock);
        //
        // _this.detailPanel.on("open", function () {
        //     _this.trigger("openDetail");
        // });
        //
        // _this.detailPanel.on("close", function () {
        //     _this.trigger("closeDetail");
        //     _this.unActiveAllItem();
        // });
        //
        // _this.panels.push(_this.detailPanel);


        _this.app.ui.layout.right.append(_this.listPanel);
        // _this.app.ui.layout.left.append(_this.detailPanel);


        _this.layer = new Layer({
            "app": _this.app
        });

        _this.layer.pointPrimitives = _this.layer.primitives.add(new uEarth.PointPrimitiveCollection());
        _this.layer.labelPrimitives = _this.layer.primitives.add(new uEarth.LabelCollection());
        _this.layer.billboardPrimitives = _this.layer.primitives.add(new uEarth.BillboardCollection());


    }

    var _class = MaintainStaModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "loadDamageType"     : {
            value: function (data, callback) {

                var _this = this;
                if (_this.damageTypeRequest) {
                    _this.damageTypeRequest.send(data, function (json) {
                        if (json.data.list && json.data.list.length > 0) {
                            callback && callback(json.data.list);
                        }
                    });
                }
            }
        },
        "loadInit"           : {
            value: function (callback, forceReload) {

                var _this = this;

                if (forceReload || !_this.isLoaded) {

                    var queryNode = _this.app.queryManager.add(new QueryNode({
                        "title"   : "[模块] : " + _this.title,
                        "modality": true
                    }));

                    queryNode.trigger("send");

                    _this.loadMap(function (mapData) {
                        _this.loadDamageType({}, function (damageTypeJson) {
                            _this.app.modules.road.roadLineModule.loadInit(function () {

                                queryNode.trigger("loaded");

                                _this.stakeNumPanel._startStakeNum = _this.app.modules.road.stakeNumModule.startStakeNum;
                                _this.stakeNumPanel._stopStakeNum = _this.app.modules.road.stakeNumModule.stopStakeNum;
                                _this.stakeNumPanel.update();

                                _this.globeButtonPanel.startStakeNumInput.value = _this.stakeNumPanel.startStakeNum.no;
                                _this.globeButtonPanel.stopStakeNumInput.value = _this.stakeNumPanel.stopStakeNum.no;

                                if (mapData) {
                                    _this.objMap = mapData.obj;
                                    _this.propertiesMap = mapData.properties;
                                    _this.dic = mapData.dic;
                                }

                                if (damageTypeJson) {
                                    _this.damageType = damageTypeJson;
                                }

                                _this.listPanel.listBlock.damageMainTypeSelect.setList(
                                    (function () {
                                        var list = [{
                                            "text" : "全部",
                                            "value": ""
                                        }];

                                        $.each(_this.damageType, function (i, type) {
                                            list.push({
                                                "text" : type.title,
                                                "value": type.title
                                            });
                                        });

                                        return list;
                                    }())
                                );

                                _this.listPanel.listBlock.damageDegreeSelect.setList(
                                    (function () {
                                        var list = [{
                                            "text" : "全部",
                                            "value": ""
                                        }];

                                        $.each(_this.dic.damageDegrees, function (label, damageDegree) {
                                            list.push({
                                                "text" : label,
                                                "value": label
                                            });
                                        });

                                        return list;
                                    }())
                                );


                                _this.globeButtonPanel.typeSelect.setList(
                                    (function () {
                                        var list = [];

                                        $.each(_this.dic.checkTypes, function (type, value) {
                                            list.push({
                                                "text" : type,
                                                "value": value
                                            });
                                        });

                                        return list;
                                    }())
                                );

                                _this.globeButtonPanel.damageMainTypeSelect.setList(
                                    (function () {
                                        var list = [{
                                            "text" : "全部",
                                            "value": ""
                                        }];

                                        $.each(_this.damageType, function (i, type) {
                                            list.push({
                                                "text" : type.title,
                                                "value": type.title
                                            });
                                        });

                                        return list;
                                    }())
                                );

                                _this.globeButtonPanel.damageMainTypeSelect.on("select", function (select) {

                                    if (select.value !== undefined) {

                                        var list = [{
                                            "text" : "全部",
                                            "value": ""
                                        }];
                                        $.each(_this.damageType, function (i, type) {
                                            if (type.title === select.value) {

                                                $.each(type.children, function (j, subtype) {
                                                    list.push({
                                                        "text" : subtype.title,
                                                        "value": subtype.title
                                                    });
                                                });
                                            }

                                        });
                                        _this.globeButtonPanel.damageTypeSelect.setList(list);

                                    } else {
                                        _this.globeButtonPanel.damageTypeSelect.disable();
                                    }

                                });

                                _this.globeButtonPanel.damageMainTypeSelect.trigger("select");
                                _this.globeButtonPanel.detailButton.trigger("click");

                                _this.initStaticTable();

                                _this.isLoaded = true;
                                _this.trigger("loadInit");

                                callback && callback();

                            });

                        });


                    });

                } else {
                    callback && callback();
                }


            }
        },
        "data"               : {
            set: function (data) {
                var _this = this;
                _this.clear();
                _this._data = data;
                data && _this.renderList(data);
            },
            get: function () {
                return this._data;
            }
        },
        "renderList"         : {
            value: function (list) {

                var _this = this;

                $.each(list, function (i, item) {

                    if (_this.objMap) {
                        item = _this.objMap.format(item);
                    }

                    item.app = _this.app;
                    item.icon = _this.icon;
                    item.dic = _this.dic;
                    item.damageTypeDic = _this.damageType;
                    item.module = _this;

                    if (item["车道"] && /第[一二三]车道/.test(item["车道"])) {

                        var roadTrackNo = ["一", "二", "三"].indexOf(item["车道"].charAt(1)) + 1;

                        item.roadTrack = {
                            "no"             : roadTrackNo,
                            "northRoadLineNo": roadTrackNo + (item["朝向"] === "上行" ? -1 : 0),
                            "southRoadLineNo": roadTrackNo + (item["朝向"] === "上行" ? 0 : -1)
                        };

                    }

                    if (item["朝向"] && item["朝向"] !== "-" && item["roadTrack"] && item["桩号"]) {

                        var positionHeading = _this.app.modules.road.roadLineModule.getSampledRoadTrackPositionHeading(
                            {
                                "direction" : item["朝向"],
                                "roadLineNo": item["roadTrack"].northRoadLineNo
                            },
                            {
                                "direction" : item["朝向"],
                                "roadLineNo": item["roadTrack"].southRoadLineNo
                            },
                            item["桩号"]
                        );

                        if (positionHeading) {
                            item.positionHeading = positionHeading;
                        }

                    }


                    var maintain = new Maintain(item);
                    _this.items.push(maintain);

                    maintain.listItem = new ListItem({
                        "title"   : maintain.title,
                        "subtitle": maintain["位置"],
                        "icon"    : _this.icon.base64,
                        "maintain": maintain,
                        "class"   : "maintain"
                    });

                    if (maintain.damageMainType) {
                        maintain.listItem.addClass("type_" + maintain.damageMainType.code);
                    }

                    maintain.block = new MaintainBlock({
                        properties    : maintain,
                        modalityWindow: _this.app.modalityWindow
                    });

                    maintain.openPop = function () {
                        maintain.block.load();
                        maintain.speak();
                        _this.app.pop.target = maintain;
                        _this.app.pop.content = maintain.block;
                        _this.app.pop.position = maintain.position;
                        _this.app.pop.one("close", function () {
                            _this.app.speaker.stop();
                            maintain.active(false);
                            maintain.trigger("closePop");
                        });
                        _this.app.pop.open();
                    };

                    maintain.on("click", function () {
                        _this.activeItem(maintain);
                        maintain.openPop();
                    });

                    maintain.on("close", function (maintain) {
                        if (_this.app.pop.target === maintain) {
                            _this.app.pop.close();
                        }
                    });

                    maintain.listItem.on("click", function () {
                        _this.activeItem(maintain);

                        if (maintain.viewport) {

                            _this.app.earth.camera.flyToBoundingSphere(
                                maintain.viewport.boundingSphere,
                                {
                                    offset: maintain.viewport.hpr
                                });
                        }

                        // _this.detailPanel.propertiesBlock.title = maintain.title;
                        // _this.detailPanel.propertiesBlock.map = _this.propertiesMap;
                        // _this.detailPanel.propertiesBlock.properties = maintain;
                        // _this.detailPanel.open();
                    });

                    maintain.listItem.on("hide", function (listItem) {
                        listItem.maintain.close();
                    });

                    maintain.listItem.on("show", function (listItem) {
                        listItem.maintain.open();
                    });

                    _this.listPanel.listBlock.add(maintain.listItem);

                });

                _this.listPanel.listBlock.filter.list = _this.listPanel.listBlock.list;
                _this.listPanel.listBlock.sorter.list = _this.listPanel.listBlock.list;

                _this.countStaticTable();
            }
        },
        "initStaticTable"    : {
            value: function () {
                var _this = this;

                _this.statisticsPanel.dataTable = {};

                var table = new mhjs.Table();
                var thead = new mhjs.Thead();
                var tbody = new mhjs.Tbody();

                table
                    .append(thead)
                    .append(tbody)
                ;

                var theadtr = new mhjs.Tr();
                var theadtr2 = new mhjs.Tr();

                thead
                    .append(theadtr)
                // .append(theadtr2)
                ;

                $.each(["序号", "方向", "车道", "桩号"], function (i, item) {
                    var th = new mhjs.Th();
                    th.text(item);
                    th.attr("rowspan", 2);
                    theadtr.append(th);
                });

                $.each(_this.damageType, function (i, type) {
                    var th = new mhjs.Th();
                    th.text(type.title);
                    th.attr("colspan", 2);
                    theadtr.append(th);

                    var th2 = new mhjs.Th();
                    th2.text("病害等级");
                    theadtr2.append(th2);

                    var th3 = new mhjs.Th();
                    th3.text("条数");
                    theadtr2.append(th3);
                });

                $.each(_this.directionDic, function (i, direction) {

                    _this.statisticsPanel.dataTable[direction.text] = {};

                    $.each(_this.roadLineDic, function (j, roadline) {

                        _this.statisticsPanel.dataTable[direction.text][roadline.text] = {};

                        for (var k = _this.stakeNumPanel.startStakeNum.no; k < _this.stakeNumPanel.stopStakeNum.no; k++) {

                            _this.statisticsPanel.dataTable[direction.text][roadline.text][k] = {};

                            var tr = new mhjs.Tr();

                            var td0 = new mhjs.Td();
                            tr.append(td0);

                            var td = new mhjs.Td();
                            td.text(direction.text);
                            tr.append(td);

                            var td2 = new mhjs.Td();
                            td2.text(roadline.text);
                            tr.append(td2);

                            var td3 = new mhjs.Td();
                            td3.text("K" + k + " 至 " + "K" + (k + 1));
                            tr.append(td3);

                            $.each(_this.damageType, function (i, type) {

                                _this.statisticsPanel.dataTable[direction.text][roadline.text][k][type.title] = {};
                                var currentData = _this.statisticsPanel.dataTable[direction.text][roadline.text][k][type.title];

                                var td4 = new mhjs.Td();
                                td4.text("重度");
                                tr.append(td4);

                                var td5 = new mhjs.Td();
                                td5.text("/");
                                tr.append(td5);

                                currentData.tr = tr;
                                currentData.td = td5;
                                currentData.items = [];

                            });

                            tbody.append(tr);

                        }


                    });
                });


                _this.statisticsPanel.tableBlock.content = table;


            }
        },
        "countStaticTable"   : {
            value: function () {

                var _this = this;

                $.each(_this.statisticsPanel.dataTable, function (i, roadlines) {
                    $.each(roadlines, function (k, stakeNums) {
                        $.each(stakeNums, function (l, damageTypes) {
                            $.each(damageTypes, function (l, currentO) {
                                currentO.tr.hide();
                                currentO.td.text("/");
                                currentO.items = [];

                            });
                        });
                    });
                });

                $.each(_this.items, function (i, item) {
                    if (item["朝向"] && item["车道"] && item.stakeNum && item["病害主类型"]) {

                        if (_this.statisticsPanel.dataTable.getChainChild(item["朝向"] + "." + item["车道"] + "." + item.stakeNum.no + "." + item["病害主类型"])) {
                            var currentO = _this.statisticsPanel.dataTable.getChainChild(item["朝向"] + "." + item["车道"] + "." + item.stakeNum.no + "." + item["病害主类型"]);
                            currentO.items.push(item);
                            currentO.tr.show();
                            currentO.td.text(currentO.items.length + "条");
                        }
                    }
                });

                var no = 1;

                $.each(_this.statisticsPanel.tableBlock.ui.wrap.find("tbody tr:visible"), function (i, jo) {
                    $(jo).find("td").eq(0).text(no);
                    no++;
                });

            }
        },
        "clear"              : {
            value: function () {
                var _this = this;

                $.each(_this.items, function (i, item) {
                    item.close();
                    item.listItem.remove();
                });

                _this._data = undefined;
                _this.items = [];
            }
        },
        "objMap"             : {
            set: function (objMap) {
                var _this = this;
                _this._objMap = new mhjs.Map(objMap);
            },
            get: function () {
                return this._objMap;
            }
        },
        "propertiesMap"      : {
            set: function (propertiesMap) {
                var _this = this;
                _this._propertiesMap = new mhjs.Map(propertiesMap);
            },
            get: function () {
                return this._propertiesMap;
            }
        },
        "open"               : {
            value: function (forceReload) {
                var _this = this;

                _this.loadInit(function () {
                    _this.isOpened = true;
                    $.each(_this.items, function (i, item) {
                        item.open();
                    });

                    _this.layer.open();

                    _this.globeChartPanel.open(false);
                    _this.globeChartPanel.max(false);
                    _this.globeDataPanel.open(false);
                    _this.globeButtonPanel.open(false);
                    _this.stakeNumPanel.open(false);
                    _this.listPanel.open(false);
                    _this.listPanel.max(false);


                    _this.trigger("open");
                    _this.trigger("toggle");
                }, forceReload);
            }
        },
        "renderData"         : {
            value: function (option, callback) {
                var _this = this;

                if (option && option.simpleEqual(_this.currentStatisticsOption)) {
                    callback && callback();
                } else {

                    _this.app.queryManager.modalityLoading.open();
                    _this.app.queryManager.modalityLoading.info = "正在加载数据";

                    _this.loadData(option, function (result) {
                        _this.currentStatisticsOption = option;
                        _this.data = result;
                        _this.updateChart();
                        _this.updateStakeNumPoint();
                        _this.globeDataPanel.damageCountData.count = _this.data ? _this.data.length : 0;

                        _this.app.queryManager.modalityLoading.close();
                        callback && callback(result);
                    });
                }
            }
        },
        "updateChart"        : {
            value: function () {
                var _this = this;

                var list = _this.items;
                var damageTypeSeries = {};
                var damageTypeLegend = [];
                var damageDegreeLegend = [];
                var damageDegreeSeries = {};
                var yearLegend = [];
                var yearSeries = {};

                $.each(_this.damageType, function (i, damageType) {
                    // if (obj.type === Number(_this.currentStatisticsOption.type)) {
                    damageTypeLegend.push(damageType.title);
                    damageTypeSeries[damageType.title] = 0;
                    // }
                });

                $.each(_this.dic.damageDegrees, function (damageDegree, obj) {
                    damageDegreeLegend.push(damageDegree);
                    damageDegreeSeries[damageDegree] = 0;
                });

                $.each(list, function (i, maintain) {
                    if (maintain["病害主类型"]) {
                        damageTypeSeries[maintain["病害主类型"]] += 1;
                    }
                    if (maintain["病害程度"]) {
                        damageDegreeSeries[maintain["病害程度"]] += 1;
                    }

                    if (maintain["巡查时间"]) {

                        var time = new Date(maintain["巡查时间"]);

                        if (yearLegend.indexOf(time.getFullYear() + "") < 0) {
                            yearLegend.push(time.getFullYear() + "");
                        }

                        yearSeries[time.getFullYear() + ""] = (yearSeries[time.getFullYear() + ""] || 0) + 1;
                    }

                });

                _this.globeChartPanel.damageTypeBlock.chart.setOption(
                    {
                        legend: {
                            data: damageTypeLegend
                        },
                        series: {
                            data: (function () {
                                var list = [];
                                $.each(_this.damageType, function (i, damageType) {
                                    // if (damageTypeSeries[damageType.title] > 0) {
                                    list.push({
                                        "name" : damageType.title,
                                        "value": damageTypeSeries[damageType.title]
                                        // ,"itemStyle": {
                                        //     "color": obj.color
                                        // }
                                    });
                                    // }
                                });
                                return list;
                            }())
                        }
                    }
                );

                _this.globeChartPanel.damageDegreeBlock.chart.setOption(
                    {
                        legend: {
                            data: damageDegreeLegend
                        },
                        series: {
                            data: (function () {
                                var list = [];
                                $.each(_this.dic.damageDegrees, function (damageDegree, obj) {
                                    // if (damageDegreeSeries[damageDegree] > 0) {
                                    list.push({
                                        "name"     : damageDegree,
                                        "value"    : damageDegreeSeries[damageDegree],
                                        "itemStyle": {
                                            "color": obj.color
                                        }
                                    });
                                    // }
                                });
                                return list;
                            }())
                        }
                    }
                );

                _this.globeChartPanel.yearBlock.chart.setOption(
                    {
                        legend: {
                            data: yearLegend
                        },
                        series: {
                            data: (function () {
                                var list = [];
                                $.each(yearLegend, function (i, year) {
                                    list.push({
                                        "name" : year,
                                        "value": yearSeries[year]
                                    });
                                });
                                return list;
                            }())
                        }
                    }
                );

            }
        },
        "updateStakeNumPoint": {
            value: function () {
                var _this = this;
                var list = _this.items;
                _this.stakeNumPanel.clearStakeNumPointData();
                $.each(list, function (i, maintain) {
                    maintain.stakeNumPanelPoint = _this.stakeNumPanel.addStakeNumPointData(maintain.stakeNum.str, maintain.damageDegree && maintain.damageDegree.color || "#fff");

                    maintain.on("close", function (maintain) {
                        maintain.stakeNumPanelPoint && maintain.stakeNumPanelPoint.hide();
                    });

                    maintain.on("open", function (maintain) {
                        maintain.stakeNumPanelPoint && maintain.stakeNumPanelPoint.show();
                    });

                });
            }
        },
        "openStatistics"     : {
            value: function () {
                var _this = this;
                _this.globeChartPanel.min(false);
                _this.listPanel.min(false);
                _this.statisticsPanel.open(false);
                _this.globeButtonPanel.addClass("statisticsOpen");
            }
        },
        "openDetail"         : {
            value: function () {
                var _this = this;
                _this.listPanel.max(false);
                _this.globeChartPanel.max(false);
                _this.statisticsPanel.close(false);
                _this.globeButtonPanel.removeClass("statisticsOpen");
            }
        },
        "openPanel"          : {
            value: function () {
                var _this = this;
                if (!_this.isOpened) {
                    _this.open();
                }

                _this.listPanel.open();
                _this.isPanelOpened = true;
                _this.trigger("openPanel");

            }
        },
        "close"              : {
            value: function () {
                var _this = this;
                _this.closePanel(false);
                _this.globeButtonPanel.removeClass("statisticsOpen");

                $.each(_this.items, function (i, item) {
                    item.close();
                });

                _this.layer.close();
                _this.isOpened = false;
                _this.trigger("close");
                _this.trigger("toggle");
            }
        },
        "activeItem"         : {
            value: function (item) {
                var _this = this;
                if (!item.isActive) {
                    _this.unActiveAllItem();
                    item.active();
                    item.listItem.addClass("active");
                    item.listItem.parent().animate({"scrollTop": item.listItem.dom[0].offsetTop});
                }
            }
        },
        "unActiveAllItem"    : {
            value: function () {
                var _this = this;
                $.each(_this.items, function (i, item) {
                    item.active(false);
                    item.listItem.removeClass("active");
                });
            }
        }
    });

    return _class;

});